#include <iostream>
#include <stdio.h>
using namespace std;
const int MAXN=100007;
int s[MAXN], d[MAXN];
int main() {
    int cnt=0;
    int mark=0;
    int n;
    scanf("%d", &n);
    for (int i=0; i<n; ++i) {
        scanf("%d%d", &s[i], &d[i]);
    }
    for (int i=0; i<n; ++i) {
        if (d[i] && s[i]>mark) mark=s[i];
        if (!d[i]) {
            if (s[i]<mark) ++cnt;
            else mark=-1;
        }
    }
    mark=-1;
    for (int i=n-1; i>=0; --i) {
        if (!d[i] && s[i]>mark) mark=s[i];
        if (d[i]) {
            if (s[i]<mark) ++cnt;
            else mark=-1;
        }
    }
    printf("%d\n", n-cnt);
    return 0;
}
